package com.lqk.springbootminio.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author liqiankun@nnuo.com
 * @date 2023/3/24 11:04
 * @description
 **/
@Configuration
@EnableOpenApi
public class Swagger3Config {

    /**
     * 控制是否允许swagger
     */
    @Value("${swagger.enable:false}")
    private boolean enable;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .enable(enable)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("lqk-测试项目").termsOfServiceUrl("https://gitee.com/lqk1126/minio")
                .description("API接口")
                .contact(new Contact("minio","https://gitee.com/lqk1126/minio",""))
                .version("3.0").build();
    }
}
